package sample.tomcat.tools;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by vista on 2017/6/15.
 */
public class AnnotationTool {


    @SuppressWarnings("rawtypes")
    public static void getMethodInfo(Class pkgclass) {
        Class clazz = pkgclass;
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            String methodName = method.getName();
            System.out.println("方法名称:" + methodName);
            Class<?>[] parameterTypes = method.getParameterTypes();
            for (Class<?> clas : parameterTypes) {
                String parameterName = clas.getName();
                System.out.println("参数名称:" + parameterName);
            }
            System.out.println("*****************************");


            //方法的返回值
            System.out.println(" returnType: ");
            Type returnType = method.getGenericReturnType();// 返回类型
            System.out.println("  " + returnType);
            /**如果是泛型类型 */
            if (returnType instanceof ParameterizedType){
                Type[] types = ((ParameterizedType) returnType).getActualTypeArguments();
                // 泛型类型列表
                System.out.println("  TypeArgument: ");
                for (Type type : types) {
                    System.out.println("   " + type);
                }
            }
        }



    }
}
